<%--
  Created by IntelliJ IDEA.
  User: j
  Date: 2021/11/22
  Time: 8:41
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="/static/css/bootstrap.css">
    <script src="/static/js/jquery-3.2.1.js"></script>
    <script src="/static/js/bootstrap.js"></script>
    <title>Title</title>

</head>
<body>
    <form action="./add" method="post">
        订单编号:<input name="oid" value="${oid}" readonly="readonly">
        下单时间:<input type="text" name="odate" onclick="WdatePicker({dateFmt:'yyyy-MM-dd'})"><br>
        仓库:<input name="warsehouse">
        订货人:<input name="orderer"><br><br>
        库位:<input name="location">
        物流单号:<input name="trackingNumber"><br><br>
        总金额:<input name="sum" readonly="readonly"><span id="sp_sum" ></span>
        附件成本:<input name="cost"><span id="sp_cost"></span><br><br>
        折让金额:<input name="discountAmount"><span id="sp_discountamount"></span>
        制单人:<input name="credit" value="${user.userName}"><br><br>
        交货方式:
        <select name="way">
            <option value="送货上门">送货上门</option>
            <option value="自主取货">自主取件</option>
        </select>

        交货地点:<input name="address"><br><br>
        <table border="1">
            <input type="button" value="增加" onclick="addTr()">
        <tr>
            <td>商品编号</td>
            <td>商品每次</td>
            <td>型号</td>
            <td>单价</td>
            <td>数量</td>
            <td>金额</td>
            <td>备注</td>
            <td>操作</td>
        </tr>
        <tr>
            <td><input name="orderGoodsList[0].id" style="width: 100px"></td>
            <td><input name="orderGoodsList[0].gname" style="width: 100px"></td>
            <td><input name="orderGoodsList[0].type" style="width: 100px"></td>
            <td><input name="orderGoodsList[0].unit" style="width: 100px" onblur="js(0)"></td>
            <td><input name="orderGoodsList[0].number" style="width:100px" onblur="js(0)"></td>
            <td><input name="pro0" style="width: 100px" class="aaa"></td>
            <td><input name="orderGoodsList[0].remark" style="width: 100px"></td>
            <td><input type="button" value="删除" onclick="delTr(this)"></td>
        </tr>
        </table>

        <input type="button" value="提交" onclick="tj()">
    </form>
<script>
    function delTr(thiz){
        $(thiz).parent().parent().remove();
    }
    function js(s){
      var a=  $("[name='orderGoodsList["+s+"].unit']").val();
      var b=  $("[name='orderGoodsList["+s+"].number']").val();
      $("[name='pro"+s+"']").val(Number(a*b));

    //获取所有class
        var cc=0;
        $(".aaa").each(function (){
            cc+=Number($(this).val());
        });
        $("[name='sum']").val(cc);
    }

    function yz(){
        //验证总金额
      var sum=  $("[name='sum']").val();
      var tes=/^\d+(\.+\d{1,2})?$/;
        // if (!tes.test(sum)){
        //    $("#sp_sum").text("总金额不是整数,1,2位小数");
        //    return;
        // }
        //验证附件成本
        var cost=  $("[name='cost']").val();

        if (!tes.test(cost)){
            $("#sp_cost").text("附件成本不是整数,1,2位小数");
            return;
        }

    //验证折让金额
        var discountamount=  $("[name='discountAmount']").val();

        if (!tes.test(discountamount)){
            $("#sp_discountamount").text("折让金额不是整数,1,2位小数");
            return;
        }
    }
    function tj(){
        $("span").text("");
        yz();
        if ($("span").text()==""){
            var url="add?"+$('form').serialize();
            $("#nav-tabContent").load(url);
        }

    }

    var  i=1;
    function addTr(){
      $("table").append('<tr>' +
          '<td><input name="orderGoodsList['+i+'].id"  style="width: 100px"></td>' +
          '<td><input name="orderGoodsList['+i+'].gname" style="width: 100px"></td>' +
          '<td><input name="orderGoodsList['+i+'].type" style="width: 100px"></td>' +
          '<td><input name="orderGoodsList['+i+'].unit" style="width: 100px" onblur="js('+i+')"></td>' +
          '<td><input name="orderGoodsList['+i+'].number" style="width: 100px" onblur="js('+i+')"></td>' +
          '<td><input name="pro'+i+'" style="width: 100px" class="aaa"></td>' +
          '<td><input name="orderGoodsList['+i+'].remark" style="width: 100px"></td>' +
          '<td><input type="button" value="删除" onclick="delTr(this)"></td>'+
          '</tr>');
      i++;
    }

</script>
</body>
</html>
